# -*- coding: UTF-8 -*-

from .models import BaseModel

from .addons_models import addons_models


class Environment(object):
    def __init__(self, rpc):
        self.rpc = rpc

    def model(self, model):
        return self._create_model_class(model)

    def _create_model_class(self, model):
        env1 = self

        addons_models2 = {}
        addons_models2.update(addons_models)
        addons_models2.update(self.rpc.addons_models)

        BaseModel2 = addons_models2.get(model, BaseModel)

        class MetaModel(BaseModel2):
            _env = env1
            _model = BaseModel2._model or model

        return MetaModel
